package com.nokia.ion.sdu.cdr_decoder;

import com.alibaba.fastjson.JSON;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Configuration {
    public String outputType;
    public String startTime;
    public String endTime;
    public boolean optimize;
    public int numOfReadThread;

    public String rawCdrDir;
    public String[] rawCdrFiles;

    public Sqlite3Configure sqlite3;
    public MysqlConfigure mysql;
    public AnalysisConfigure analysis;
    public ElasticsearchConfigure elasticsearch;

    public static Configuration parseConfiguration() throws IOException {
        InputStream inputStream = new FileInputStream("./app.json");
        String text = IOUtils.toString(inputStream, "utf8");
        return JSON.parseObject(text, Configuration.class);
    }

    public static class Sqlite3Configure {
        public String outputPath;
        public String dbName;
        public int commitBufSize;
    }

    public static class MysqlConfigure {
        public String host;
        public int port;
        public String dbName;
        public String username;
        public String password;
        public int commitBufSize;
    }

    public static class ElasticsearchConfigure {
        public String url;
        public int bulkSize;
        public int concurrentRequests;
    }

    public static class AnalysisConfigure {
        public String outputPath;
        public String csvFilename;
    }
}
